<template>
	<!-- 师傅个人中心设置 -->
	<view>
		<view class="set-list">
			<uni-list-item title="修改密码" style="fontSize: 34rpx;" link to="/pages/sf/xgmm/xgmm" clickable>
			</uni-list-item>
			<uni-list-item title="修改手机号" link to="/pages/sf/xgsj/xgsj" clickable>
			</uni-list-item>
			<uni-list-item title="修改工作状态" v-if="userInfo.is_worker == 2" link>
				<template slot="footer">
					<picker @change="bindPickerChange" :value="index"
						style="display: inline-block;width: 75%;text-align: end;" :range="preferential"
						range-key="text">
						<view class="uni-input">{{word}}</view>
					</picker>
				</template>

			</uni-list-item>
		</view>

		<button @click="loginout">安全退出</button>
	</view>
</template>

<script>
	import {
		editWorderStatus,
		userinfo
	} from "../../../api/api.js"
	export default {
		data() {
			return {
				word: "",
				status: "",
				userInfo:"",
				preferential: [{
						text: '下班',
						value: 0,
					},
					{
						text: '空闲',
						value: 1,
					},
					{
						text: '忙碌',
						value: 2,
					},
				]
			}
		},
		onShow() {
			userinfo().then(res => {
				 uni.setStorageSync('userInfo', res.data)
				 let userInfo =  uni.getStorageSync('userInfo')
				 this.userInfo = userInfo
				this.status = userInfo.work_status
				console.log('this.userInfo', this.userInfo,userInfo)
				
				if(this.status == 0){
				return	this.word = '下班';
				}
				if(this.status == 1){
				return	this.word = '空闲';
				}
				if(this.status == 2){
				return	this.word = '忙碌';
				}
				
			})

		},
		methods: {
			bindPickerChange(e) {
				console.log(e.detail.value)
				let value = e.detail.value
				this.word = this.preferential[value].text
				this.status = this.preferential[value].value
				this.finallmoney()
			},
			// 修改
			finallmoney() {
				let data = {
					work_status: this.status
				}
				editWorderStatus(data).then(res => {
					if (res.status == 200) {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				})
			},
			// 退出登录
			loginout() {
				uni.showModal({
					title: "提示",
					content: "确定退出登录吗?",
					showCancel: true,
					success: (res) => {
						if (res.confirm) {
							uni.setStorageSync('login', false)
							uni.setStorageSync('token', '')
							uni.setStorageSync('userInfo', {})
							uni.showToast({
								title: "操作成功!",
								icon: "none"
							})
							uni.navigateTo({
								url: "/pages/login/index"
							})
						}
					}
				})

			},
		}
	}
</script>

<style scoped>
	.set-list {
		padding: 0 20rpx;
	}

	/deep/.uni-list-item {
		border-bottom: 5rpx solid #F7F5F6;
		padding-top: 16rpx;
		position: static;
	}

	.uni-list-item text {
		font-size: 36rpx;
	}

	.uni-icons {
		font-size: 52rpx !important;
	}

	/deep/.uni-list-item__content-title {
		font-size: 34rpx;
	}

	button {
		margin: 100rpx auto;
		background: #029E8E;
		width: 60%;
		border-radius: 50rpx;
		color: #fff;
	}

	.uni-input {
		font-size: 26rpx;
		color: #666666;
		width: 150rpx;
	}
</style>
